package life.cqq.jwt.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.lang.invoke.MethodHandles;

@ControllerAdvice
public class GlobalExceptionHandler {

    private static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    /**
     * 处理Blog系统异常
     * @param ex
     * @return
     */
    @ExceptionHandler(JwsTokenInvalidException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Object handleJwsTokenInvalidException(JwsTokenInvalidException ex) {
//        logger.error("");
        return "";
    }

    /**
     * 处理无处处理的异常
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public Object handleException(Throwable ex) {
        logger.error("Uncaught exception", ex);
        return "";
    }
}